package com.zhoust.threadbatch.service.impl;

import com.zhoust.threadbatch.entity.User;
import com.zhoust.threadbatch.mapper.UserMapper;
import com.zhoust.threadbatch.service.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
public class TaskServerImpl implements TaskService {
    @Autowired
    private UserMapper userMapper;


    @Override
    @Async
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
    public void saveUser(int sum) {
        for (int i =0;i<10;i++){
            User user = new User();
            user.setId(10000+i+(1000*sum));
            user.setUsername("嘉文"+i+(1000*sum));
            user.setPassword("10000"+i+(1000*sum));
            user.setAge(5555);
            userMapper.insert(user);
        }
    }

    @Async
    @Override
    public void testThread1() {
        log.info("testThread1 正在执行,线程{}",Thread.currentThread().getName());
    }

    @Async
    @Override
    public void testThread2() {
        log.info("testThread2 正在执行,线程{}",Thread.currentThread().getName());
    }


}


